
listdir=$1

dir_now=`pwd`

for dir in `cat $listdir`
do
	cd $dir
	ls *.fit | grep -v "Flat" | grep -v "Dark" | grep -v "Zero" >list
	Flatcom=`ls *.fit | grep "Flat"`
	for fitfile in `cat list`
	do
                if [  -r Zero.fit ] && [ -r $Flatcom   ] && [ -r Dark.fit  ]
                then
			echo "have Zero.fit Dark.fit Flat*.fit"
			xzerodarkflatcorr.sh $fitfile $Flatcom

	        elif [  -r Zero.fit ] && [ -r $Flatcom   ] && [ ! -r Dark.fit   ]
		then
			echo "have Zero.fit, and Flat*.fit, but not Dark.fit" 
                	xzeroflatcorr.sh  $fitfile $Flatcom
                elif [  -r Zero.fit ] && [ ! -r $Flatcom   ] && [ -r Dark.fit   ]
		then
			echo "have Zero.fit Dark.fit, but not Flatcom.fit"
			xzerodarkcorr.sh $fitfile 
		elif  [ ! -r Zero.fit ] && [  -r $Flatcom   ] && [ -r Dark.fit   ]
		then
			echo "no Zero.fit, but have Dark.fit and Flat.fit"
			xdarkflatcorr.sh $fitfile $Flatcom
		elif [  -r Zero.fit ] && [ ! -r $Flatcom   ] && [ ! -r Dark.fit   ]
		then
			echo "only have Zero.fit"
			xzerocorr.sh  $fitfile 
		elif [  ! -r Zero.fit ] && [  -r $Flatcom   ] && [ ! -r Dark.fit   ]
		then
			echo "only have Flat.fit"
			xflatcorr.sh $fitfile $Flatcom
		elif [  ! -r Zero.fit ] && [  ! -r $Flatcom   ] && [  -r Dark.fit   ]
		then
			echo "only have Dark.fit"
			xdarkcorr.sh $fitfile
		elif [  ! -r Zero.fit ] && [  ! -r $Flatcom   ] && [  ! -r Dark.fit   ]
		then
			echo "no Zero.fit, no Dark.fit, no Flat.fit for $dir_now"
		fi

	done
done
echo "data process is over"
